﻿using System.Windows;
using Bookvar.ObjectModel;
using Bookvar.ObjectModel.Actions;

namespace Bookvar.UI.DragDrop.Actions
{
    public class TopicCopyDropAction : TopicDropActionBase
    {
        public override void Execute(CompositeAction compositeAction, TopicContentPresenter presenter, Point dropPoint )
        {
            //do nothing, whole execution is handled here
        }

        public override void Execute(DragEventArgs args, MindMapPanel panel, Point dropPoint)
        {
            TopicContentPresenter presenter = null;
            TopicContentPresenter targetPresenter = GetTargetPresenter(args.Data, panel, dropPoint);

            if (args.Data.GetDataPresent(BookvarDataFormats.Topic.Name))
            {
                presenter = args.Data.GetData(BookvarDataFormats.Topic.Name) as TopicContentPresenter;
            }

            if ( presenter != null && targetPresenter != null )
            {
                Topic newTopic = presenter.Topic.Clone();

                var action = new AddTopicAction( newTopic ) { Parent = targetPresenter.Topic };
                ActionService.Execute( action );
                
                presenter.Focus();
            }
        }
    }
}
